<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>单位设置</title>
<%@ include file="../../common_header.jsp" %>
<script type="text/javascript" src="${ctx}/js/other.js"></script>
<style type="text/css" media="screen">
.btn{
   	border-right: #63B8FF 1px solid;
  	padding-right: 2px;
   	border-top: #63B8FF 1px solid;
   	padding-left: 2px;
   	font-size: 12px;
   	FILTER: progid:DXImageTransform.Microsoft.Gradient(GradientType=0,  StartColorStr=#ffffff,  EndColorStr=#C3DAF5);
   	border-left: #63B8FF 1px solid;
   	cursor: hand;
   	color: black;
   	padding-top: 2px;
   	border-bottom: #63B8FF 1px solid;
}
</style>
</head>
<body class="easyui-layout">
    <div data-options="region:'center',border:false" style="overflow: hidden;padding:0px" fit="true">
        <table id="dg" class="easyui-treegrid" title="单位列表" fit="true" fitColumns="false"
            url="${ctx }/manage/sysDepartment/dataGrid" method="get" data-options="toolbar:'#toolbar',width:500,fitColumns:'false'" 
            pagination="true" rownumbers="true" singleSelect="false" idField="id" treeField="text">    
            <thead>    
                <tr> 
                	<th data-options="field:'ck',checkbox:true">全选</th>
                	<th field="text" width="120" align="left">单位名称</th>   
                    <th field="depType" width="50" formatter="showType" align="center">单位类型</th>
                    <th field="address" width="150" align="left">单位地址</th>
                    <th field="phone" width="80" align="center">电话</th>
                    <th field="icon" width="70" align="center" formatter="showIcon">校徽</th>
                    <th field="desction" width="150" align="center">说明</th>
                    <th field="status" width="70" formatter="showStatus" align="center">状态</th>
                    <th data-options="field:'_operate',width:100,align:'center',formatter:formatOper">操作</th>
                </tr>    
            </thead>    
        </table>
    </div> 
    <!-- 功能菜单 -->
    <div id="toolbar" style="display: none;background: #F0FFF0" align="left">
    		${buttons }
            <script type="text/javascript">
            function append()
            {
                var params = {
                        winId:'win_add_department',
                        title:'添加部门',
                        width:450,
                        height:500,
                        showUrl:'${ctx }/manage/sysDepartment/add',
                        refresh_fun:function(){
                            $('#dg').treegrid('reload');
                        }
                        
                };
                open_fun(params);
            }
            function edit()
            {
                var moduleId=0;
                var row = $('#dg').datagrid('getSelected');
                if(row)
                {
                    moduleId = row.id;
                }
                if(moduleId>0)
                {
                    //winId,title,width,height,showUrl,okUrl,refresh_fun
                    var params = {
                            winId:'win_edit_department',
                            title:'修改部门',
                            width:450,
                            height:500,
                            showUrl:'${ctx }/manage/sysDepartment/edit?id='+moduleId,
                            refresh_fun:function(){
                                $('#dg').treegrid('reload');
                            }
                            
                    };
                    open_fun(params);   
                }
                else
                {
                    $.messager.alert("系统提示","请选择要修改的信息!");
                }
            }
            function deleteit()
            {
                var row = $('#dg').datagrid('getSelected');
                if(!row)
                {
                    $.messager.alert("系统提示","请选择要删除的数据！");
                }
                else
                {
                    $.messager.confirm("删除确认","是否要删除你选择的数据？",function(conf){
                        if(conf)
                        {
                            var url = "${ctx }/manage/sysDepartment/delete?id="+row.id;
                            $.getJSON(url, function(json){
                                if(json.success==0)
                                {
                                    $('#dg').treegrid('reload');
                                }
                                else
                                {
                                    showErrMsg(json);
                                }
                            });
                        }                                       
                    });
                }
                
            }
            
            function removeit()
            {
                var row = $('#dg').datagrid('getSelected');
                if(!row)
                {
                    $.messager.alert("系统提示","请选择要移除的数据！");
                }
                else
                {
                    $.messager.confirm("移除确认","是否要移除你选择的数据到回收站？",function(conf){
                        if(conf)
                        {
                            var url = "${ctx }/manage/sysDepartment/remove?id="+row.id;
                            $.getJSON(url, function(json){
                                if(json.success==0)
                                {
                                    $('#dg').treegrid('reload');
                                }
                                else
                                {
                                    showErrMsg(json);
                                }
                            });
                        }                                       
                    });
                }
                
            }
            
            function searchit() {
				$("#dg").datagrid("load", sy.serializeObject($('#formModule').form()));
			}
        	//右侧菜单
			function formatOper(val, row, index) {
				return '<a href="#" onclick="editone();"><input class="btn" type="button" value="修改" ></a>  <a href="#" onclick="deleteone();"><input class="btn" type="button" value="删除" ></a>  <a href="#" onclick="removeone();"><input class="btn" type="button" value="移除" ></a>';
			}
			 //以下三个函数为单个操作
	        function editone(){
	        	var row = $('#dg').datagrid('getSelected');
	        	var id = row.id;
	        	var name = row.text;
	            var params = {
	                    winId:'win_edit_sysCustomer',
	                    title:'修改 '+name+' 的信息',
	                    width:450,
	                    height:500,
	                    showUrl:'${ctx}/manage/sysDepartment/edit?id='+id,
	                    refresh_fun:function(){
	                        $('#dg').datagrid('reload');
	                    }
	            };
	            open_fun(params);   
	        }
	        function removeone(){
	        	var row = $('#dg').datagrid('getSelected');
	        	var id = row.id;
	        	var name = row.text;
	        	 $.messager.confirm("移除确认",'移除&nbsp; <span style="color:red;font-weight:bold">'+id+'-'+name+'</span> &nbsp;？',function(conf){
	                 if(conf)
	                 {
	                	 var url = "${ctx }/manage/sysDepartment/remove?id="+row.id;
	                     $.getJSON(url, function(json){
	                         if(json.success==0)
	                         {
	                             $('#dg').datagrid('reload');
	                         }
	                         else
	                         {
	                             showErrMsg(json);
	                         }
	                     });
	                 }                                       
	             });
	        }
	        function deleteone(){
	        	var row = $('#dg').datagrid('getSelected');
	        	var id = row.id;
	        	var name = row.text;
	        	 $.messager.confirm("删除确认",'删除&nbsp; <span style="color:red;font-weight:bold">'+id+'-'+name+'</span> &nbsp;？',function(conf){
	                 if(conf)
	                 {	
	                     var url = "${ctx}/manage/sysDepartment/delete?ids="+id;
	                     $.getJSON(url, function(json){
	                         if(json.success==0)
	                         {
	                             $('#dg').datagrid('reload');
	                         }
	                         else
	                         {
	                        	 showErrMsg(json);
	                         }
	                     });
	                 }                                       
	             });
	        }
            </script>
    </div>
    
    <script type="text/javascript">
        var updateFlag=false;
         $(document).ready(init);
         function init() {
             $('#dg').treegrid({             
                 onLoadSuccess: function(row,data) {
                    if(data.success != 0)
                    {
                        showErrMsg(data);
                    }
                 }
             });
         }    
        
       //状态格式化
         function showType(value,rec,index)
         {
         	if(value == 1)
         	{
         		return "<font color='green'>学校</font>";
         	}
         	else if(value == 2)
         	{
         		return "<font color='blue'>商家</font>";
         	}
         	else 
         	{
         		return "<font color='orange'>其他</font>";
         	}

         }
       
         function showIcon(value,rec,index)
         {
         	if(value != null && value != '')
         	{
         		return "<img src='"+ value +"' width='30' height='30' />";
         	}
         	else
         	{
         		return "";
         	}
         }   

    </script>
    
  </body>
</html>
